#include "misc.h"


void transformPointsForward(vector<Point2f>&origin, const Mat &H)
{
	vector<Point2f> dst;
	for (int i = 0; i<origin.size(); i++) {
		auto &a = origin[i];
		double *aa = (double*)H.data;
		double s = aa[6] * a.x + aa[7] * a.y + aa[8];
		Point2f aaa;
		aaa.x = (aa[0] * a.x + aa[1] * a.y + aa[2]) / s;
		aaa.y = (aa[3] * a.x + aa[4] * a.y + aa[5]) / s;
		dst.push_back(aaa);
	}
	origin = dst;
}

void transformPointsInverse(vector<Point2f>&origin, const Mat &H)
{
	Mat invH;
	invert(H, invH);
	vector<Point2f> dst;
	for (int i = 0; i<origin.size(); i++) {
		auto &a = origin[i];
		double *aa = (double*)invH.data;
		double s = aa[6] * a.x + aa[7] * a.y + aa[8];
		Point2f aaa;
		aaa.x = (aa[0] * a.x + aa[1] * a.y + aa[2]) / s;
		aaa.y = (aa[3] * a.x + aa[4] * a.y + aa[5]) / s;
		dst.push_back(aaa);
	}
	origin = dst;
}